package controllers.warehouse;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lib_model.Factories.Factory;
import lib_model.Orther.ReturnObj;
import lib_model.WareHouse.Warehouse;

/**
 * Servlet implementation class AddFactoties
 */
@WebServlet("/warehouse/AddWarehouse")
public class AddWarehouse extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public AddWarehouse() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("txtName");
		String description = request.getParameter("txtDes");
		String localtion = request.getParameter("txtLoc");
		int status = (Integer.parseInt(request.getParameter("txtSta")));
		RequestDispatcher dis = request
				.getRequestDispatcher("../administrator/warehouse.jsp");
		if (name != null && description != null && localtion != null) {
			Warehouse w = new Warehouse();
			w.name = name;
			w.description = description;
			w.location = localtion;
			w.status = status;
			ReturnObj obj = w.Add();
			if (obj.Result == true) {
				System.out.println(obj.Result);
				request.setAttribute("Mes", "Suscessfull !");
			} else {
				System.out.println(obj.Result);
				request.setAttribute("Mes", "Error ! Can't create warehouse");
			}
		} else {
			request.setAttribute("Mes", "Error ! Can't create warehouse");
		}
		dis.forward(request, response);
	}
}
